Speed up generation by threading seeds instead of splitting them in non-Gen part of GenT
#57
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The normal
Genmonad always splits the seed when doing>>=. This is for very good reasons - it lets you write generators that generate infinite data to the left of a>>=and let's your generators be very lazy!A traditional
GenT m aimplementation would inherit this splitting behaviour in order to let you keep writing infinite and lazy things to the left of>>=on theGenT mlevel. Now, the thing to realize about this is that unless your code is very carefully written to avoid it this means you're going to end up with unnecessary>>=s and thus unnecessary splits.To get around this issue of unnecessary splits we introduce a threading
GenTimplementation here that sacrifices letting you do infinite (and to some extent lazy) structures to the left of>>=on theGenT mlevel, but doesn't prohibit you from doing so on theGenlevel.This drastically reduces the number of seed splits while still letting you write lazy and infinite generators in
Genland by being a little bit more careful. It works great forconstrained-generatorsin particular, which has a tendency to be strict and by design avoids inifinte values.